$(function () {

    $.toastMsg = new function () {

        var that = this;

        this.showSuccessToast = function(e, time, call) {
                'use strict';
                that.resetToastPosition();
                $.toast({
                heading: 'Success',
                text: e.info,
                showHideTransition: 'slide',
                icon: 'success',
                loaderBg: '#f96868',
                position: 'top-right',
                hideAfter: time,
                afterHidden: call
                })

        };

        this.showWarningToast = function(e, time, call) {
                'use strict';
                that.resetToastPosition();
                $.toast({
                heading: 'Warning',
                text: e.info,
                showHideTransition: 'slide',
                icon: 'warning',
                loaderBg: '#57c7d4',
                position: 'top-right',
                hideAfter: time,
                afterHidden: call
                })
        };

        this.showDangerToast = function(e, time, call) {
                'use strict';
                that.resetToastPosition();
                $.toast({
                heading: 'Error',
                text: e.info,
                showHideTransition: 'slide',
                icon: 'error',
                loaderBg: '#f2a654',
                position: 'top-right',
                hideAfter: time,
                afterHidden: call
                })
        };
        
        this.showToast = function(e, time, call){
            switch (e.code){
                case 1:
                    that.showSuccessToast(e, time, call);
                break;
                case 0:
                    that.showDangerToast(e, time, call);
                break;
                default:
                    that.showWarningToast(e, time, call);
                break;
            }
        };
        
        this.resetToastPosition = function() {
            $('.jq-toast-wrap').removeClass('bottom-left bottom-right top-left top-right mid-center'); // to remove previous position class
            $(".jq-toast-wrap").css({
            "top": "",
            "left": "",
            "bottom": "",
            "right": ""
            }); //to remove previous position style
        }
    }

})